var SelectProduct2 = 
'<div class="modal" id="SelectProduct2" tabindex="-1" role="dialog" aria-hidden="true" >'+
	'<div class="modal-dialog" style="width: 800px !important;">'+
		'<div class="modal-content">'+
			'<div class="modal-header">'+
				'<button type="button" class="close" id="closeSP2" data-dismiss="modal" aria-hidden="true"></button>'+
				'<h4 class="modal-title">选择产品</h4>'+
				'<div class="form-box2">'+
					'<div class="have-ipt-box">'+
						'<label class="ipt-label" for="">产品编码：</label>'+
						'<input class="ipt-self1" type="text" name="code" id="productCode_s" value="" />'+
					'</div>'+
					'<div class="have-ipt-box">'+
						'<label class="ipt-label" for="">产品名称：</label>'+
						'<input class="ipt-self1" type="text" name="name" id="productName_s" value="" />'+
					'</div>'+
					/*'<div class="have-ipt-box2 icheck-success icheck-inline">'+
						'<div class="ipt-label2">当前状态：</div>'+
						'<div class="radio-box1">'+
							'<div class="icheck-success icheck-inline">'+
							    '<input type="radio" id="diivisionRadio1" value="" name="productStatus" checked="checked" />'+
							    '<label for="diivisionRadio1">全部</label>'+
							'</div>'+
							'<div class="icheck-success icheck-inline">'+
							    '<input type="radio" id="diivisionRadio2" value="0" name="productStatus" />'+
							    '<label for="diivisionRadio2">启用</label>'+
							'</div>'+
							'<div class="icheck-success icheck-inline">'+
							    '<input type="radio" id="diivisionRadio3" value="1"  name="productStatus" />'+
							    '<label for="diivisionRadio3">禁用</label>'+
							'</div>'+
						'</div>'+
					'</div>'+*/
					'<div class="form-btn-box form-btn-box2">'+
						'<button class="btn-blue" id="product-selectBtn">'+
							'<img src="../img/btn-icon/search.png"/>'+
							'<span>查询</span>'+
						'</button>'+
						'<button class="btn-green" id="product-closeBtn">'+
							'<img src="../img/btn-icon/close.png"/>'+
							'<span>关闭</span>'+
						'</button>'+
						'<button class="btn-green" id="sure-Btn">'+
							'<img src="../img/btn-icon/add.png"/>'+
							'<span>确认添加</span>'+
						'</button>'+
					'</div>'+
					'<div style="height: 510px; overflow: scroll;">'+
					'<table id="tableProduct"></table>'+
					'</div>'+
				'</div>'+
			'</div>'+
		'</div>'+
	'</div>'+
'</div>';
$('body').append(SelectProduct2);
$("#tableProduct").bootstrapTable({ // 对应table标签的id
	//url: DOMAIN+'/v1/product'+isLogin,
	method: 'get',
	cache: false,
	striped: true,
	pagination: true,
	pageSize:200,
	pageNumber: 1,
	pageList: [200, 500],
	search: false,
	showColumns: false, 
	clickToSelect: true,
	queryParams: queryParams,
	smartDisplay: false,
	columns: [{
        checkbox: true
	}, {
			field: 'code',
			title: "产品代码",
			align: "center",
			valign: "middle"
		}/*,{
			field: 'gbCode',
			title: "国标码",
			align: "center",
			valign: "middle"
		}*/, {
			field: "name",
			title: "产品名称",
			align: "center",
			valign: "middle"
		},{
			field: 'type',
			title: "类别",
			align: "center",
			valign: "middle",
            formatter: function (value, row, index) {
                return row.levelOneName + "/" + row.levelTwoName;
            }
		},{
			field: "gradeName",
			title: "产品等级",
			align: "center",
			valign: "middle"
		}/*,{
			field: "specifications",
			title: "规格",
			align: "center",
			valign: "middle"
		}*/,{
			field: "units",
			title: "单位",
			align: "center",
			valign: "middle"
		},{
			field: "suttle",
			title: "净重（公斤）",
			align: "center",
			valign: "middle"
		},{
			field: "price",
			title: "单价",
			align: "center",
			valign: "middle"
		}/*,{
			field: "division",
			title: "产地代码",
			align: "center",
			valign: "middle",
			visible: false
		}*/],/*	
	onDblClickRow: function (row) {
		selectProduct(row);
		//模拟关闭弹框
		  $('#SelectProduct2').click();
	},*/
	formatNoMatches: function() {
		return '没有找到匹配的记录';
	}
});
function queryParams(params) {
	return params;
};


function queryParamNew(params) {
		var params = {};
		params.code = $("#productCode_s").val();
		params.name = $("#productName_s").val();
		params.custNo = $("#customerNo").val();
		return params;
};
//查询
$("#product-selectBtn").click(function(){
	//新查询参数
	var url =DOMAIN+'/v1/productPrice'+isLogin;
	$('#tableProduct').bootstrapTable(
			'refreshOptions',
			{
				url: url,
				//查询参数
				queryParams: queryParamNew
			}
		);
	
})

//关闭
$("#product-closeBtn").click(function(){
	$('#SelectProduct2').click();
})

	//打开选择框时查询
	$('#SelectProduct2').on('shown.bs.modal', function () {
		$('#tableProduct').bootstrapTable(
			'refreshOptions',
			{
				url: DOMAIN+'/v1/productPrice'+isLogin,
				queryParams: queryParamNew
			}
		);
	
	})
	$("#sure-Btn").click(function () {
		var rowsProduct = $('#tableProduct').bootstrapTable('getSelections');
		var rows = $('#tableAddDetail').bootstrapTable('getData');
		var flog = false;
		if(rowsProduct.length>0){
				for(var i = 0;i<rowsProduct.length;i++){
					if(rows.length>0){
						for (var j =0 ;j<rows.length;j++) {
							if(rowsProduct[i].name==rows[j].productName){
								alert("该商品已经存在,请重新选择!");
								return false;
							}else{
								flog=true;
							}
						}
					}else if(rows.length==0){	
						flog=true;
					}else{
						flog=false;
					}
					if(flog == true){
					//var id = rowsProduct[i].id;
					var count = $('#tableAddDetail').bootstrapTable('getData').length;
					var options = $("#tableAddDetail").bootstrapTable('getOptions');
					var pid = options.pageSize * (options.pageNumber - 1) + Number(count) + 1;
					var grade = rowsProduct[i].gradeName;
					var productCode = rowsProduct[i].code;
					var productName = rowsProduct[i].name;
					var productType = rowsProduct[i].levelTwoName;
					var units = rowsProduct[i].units;
					var price = rowsProduct[i].price;
					
					$('#tableAddDetail').bootstrapTable('insertRow', {
						index: count,
						row: {
							//id: id,
							pid: pid,
							grade:grade,
							productCode:productCode,
							productName:productName,
							productType:productType,
							units:units,
							price:price,
							priceType:"价格表",
							amount:0,
							money:0
						}
					}); 
					}
				}
				$('#closeSP2').click();
		}else{
			alert("请勾选商品!");
		}
	});
	
